﻿using System.Windows.Forms;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using XNAGuiLib.Core.ActionHandling;
using XNAGuiLib.Core.Utilities;

namespace XNAGuiLib.Core.Components
{
    public class Window : GIComponent
    {

        #region Window Protected Field - _rcm
        protected ResourceContentManager _rcm;
        #endregion

        #region Window Protected Field - _assetPrefix
        protected string _assetPrefix;
        #endregion

        #region Window Protected Field - _windowBounds
        protected Rectangle _windowBounds;
        #endregion

        #region Window Protected Field - _windowState
        protected Enums.WindowState _windowState = Enums.WindowState.Normal;
        #endregion


        #region Window Protected Field - Button_Close
        /// <summary>
        /// gets the close button of this window
        /// </summary>
        protected Button Button_Close
        {
            get { return (Button)this._gics[5]; }
        }
        #endregion

        #region Window Protected Field - Button_Maximize
        /// <summary>
        /// gets the maximize button of this window
        /// </summary>
        protected Button Button_Maximize
        {
            get { return (Button)this._gics[4]; }
        }
        #endregion

        #region Window Protected Field - Button_Minimize
        /// <summary>
        /// gets the minimize button of this window
        /// </summary>
        protected Button Button_Minimize
        {
            get { return (Button)this._gics[3]; }
        }
        #endregion



        #region Window Public Field - Background
        /// <summary>
        /// gets or sets the Background object of this window
        /// </summary>
        public Background Background
        {
            get { return (Background)this._gics[0]; }
            set { this._gics[0] = value; }
        }
        #endregion

        #region Window Public Field - BackgroundOpaque
        /// <summary>
        /// sets the background opacity
        /// </summary>
        public int BackgroundOpaque
        {
            set
            {
                if (value < 0)
                    Background.Opaque(0);
                if (value > 100)
                    Background.Opaque(100);
                Background.Opaque(value);
            }
        }
        #endregion

        #region Window Public Field - Bounds
        /// <summary>
        /// gets or sets the bounds of the window
        /// </summary>
        public new Vector2 Bounds
        {
            get { return new Vector2(this._width, this._height); }
            set { this.Resize((int)value.X, (int)value.Y); }
        }

        #region Window Public Field - Width
        /// <summary>
        /// gets the width of the window
        /// </summary>
        public new int Width
        {
            get { return this._width; }
        }
        #endregion

        #region Window Public Field - Height
        /// <summary>
        /// gets the height of the window
        /// </summary>
        public new int Height
        {
            get { return this._height; }
        }
        #endregion
        #endregion


        #region Window Public Field - ContentBounds
        /// <summary>
        /// gets the bounds of the content area of this window
        /// </summary>
        public Vector2 ContentBounds
        {
            get { return this.Panel.Bounds; }
        }
        #endregion

        #region Window Public Field - ContentWidth
        /// <summary>
        /// gets the width of the content area of this window
        /// </summary>
        public int ContentWidth
        {
            get { return this.Panel.Width; }
        }
        #endregion

        #region Window Public Field - ContentHeight
        /// <summary>
        /// gets the height of the content area of this window
        /// </summary>
        public int ContentHeight
        {
            get { return this.Panel.Height; }
        }
        #endregion


        #region Window Public Field - Frame
        /// <summary>
        /// gets or sets the Frame object of this window
        /// </summary>
        public Frame Frame
        {
            get { return (Frame)this._gics[1]; }
            set { this._gics[1] = value; }
        }
        #endregion

        #region Window Public Field - FrameOpaque
        /// <summary>
        /// sets the frame opacity
        /// </summary>
        public int FrameOpaque
        {
            set
            {
                if (value < 0)
                    Frame.Opaque(0);
                if (value > 100)
                    Frame.Opaque(100);
                Frame.Opaque(value);
            }
        }
        #endregion

        #region Window Public Field - FrameHeadSize
        protected Enums.FrameHeadStyle _frameHeadSize;
        /// <summary>
        /// gets or sets the size type for the headline of the frame (normal = default)
        /// </summary>
        public Enums.FrameHeadStyle FrameHeadSize
        {
            get { return this.Frame.FrameHeadSize; }
            set
            {
                this.Frame.FrameHeadSize = value;
                this.Adjust();
            }
        }
        #endregion


        #region Window Public Field - Maximizable
        protected bool _maximizable;
        /// <summary>
        /// gets or sets if the window is maximizable
        /// </summary>
        public bool Maximizable
        {
            get { return _maximizable; }
            set
            {
                _maximizable = value;
                this.UseButton_Maximize = value;
            }
        }
        #endregion

        #region Window Public Field - Minimizable
        protected bool _minimizable;
        /// <summary>
        /// gets or sets if the window is minimizable
        /// </summary>
        public bool Minimizable
        {
            get { return _minimizable; }
            set
            {
                _minimizable = value;
                this.UseButton_Minimize = value;
            }
        }
        #endregion


        #region Window Public Field - Panel
        /// <summary>
        /// gets the Panel object of this window
        /// </summary>
        public Panel Panel
        {
            get { return (Panel)this._gics[2]; }
        }
        #endregion


        #region Window Public Field - Resizable
        protected bool _resizable = false;
        /// <summary>
        /// gets or sets if the window is resizable
        /// </summary>
        public bool Resizable
        {
            get { return _resizable; }
            set { _resizable = value; }
        }
        #endregion


        #region Window Public Field - Title
        /// <summary>
        /// gets or sets the title of this window
        /// </summary>
        public string Title
        {
            get { return this.Frame.Title; }
            set { this.Frame.Title = value; }
        }
        #endregion

        #region Window Public Field - TitleColor
        /// <summary>
        /// gets or sets the color of the title
        /// </summary>
        public Color TitleColor
        {
            get { return this.Frame.TitleColor; }
            set { this.Frame.TitleColor = value; }
        }
        #endregion

        #region Window Public Field - TitleFont
        /// <summary>
        /// gets or sets the font used for rendering the window title
        /// </summary>
        public SpriteFont TitleFont
        {
            get { return this.Frame.Label_Title.Font; }
            set { this.Frame.Label_Title.Font = value; }
        }
        #endregion


        #region Window Public Field - UseFrame
        protected bool _useFrame = true;
        /// <summary>
        /// gets or sets the flag if the frame of the window is shown/used
        /// </summary>
        public bool UseFrame
        {
            get { return this._useFrame; }
            set
            {
                this._useFrame = value;
                this.Frame.Visible = value;
                this.Resize(this._width, this._height);
            }
        }
        #endregion

        #region Window Public Field - UseBackgroundDecoration
        /// <summary>
        /// gets or sets the flag if the background decoration of the window is shown/used
        /// </summary>
        public bool UseBackgroundDecoration
        {
            get { return this.Background.UseDecoration; }
            set { this.Background.UseDecoration = value; }
        }
        #endregion

        #region Window Public Field - UseButton_Close
        protected bool _useButton_Close = true;
        /// <summary>
        /// gets or sets if the "close" button should be shown and usable
        /// </summary>
        public bool UseButton_Close
        {
            get { return this._useButton_Close; }
            set
            {
                this._useButton_Close = value;
                this.Adjust();
            }
        }
        #endregion

        #region Window Public Field - UseButton_Maximize
        protected bool _useButton_Maximize;
        /// <summary>
        /// gets or sets if the "maximize" button should be shown and usable
        /// </summary>
        public bool UseButton_Maximize
        {
            get { return this._useButton_Maximize; }
            set
            {
                this._useButton_Maximize = value;
                this._maximizable = value;
                this.Adjust();
            }
        }
        #endregion

        #region Window Public Field - UseButton_Minimize
        protected bool _useButton_Minimze;
        /// <summary>
        /// gets or sets if the "minimize" button should be shown and usable
        /// </summary>
        public bool UseButton_Minimize
        {
            get { return this._useButton_Minimze; }
            set
            {
                this._useButton_Minimze = value;
                this._minimizable = value;
                this.Adjust();
            }
        }
        #endregion



        /* Component mapping for the Window Element
         * =======================================
         * [0]  Background
         * [1]  Frame
         * [2]  Panel
         * [3]  Button_Minimize
         * [4]  Button_Maximize
         * [5]  Button_Close
         * 
         * Action mapping for the Window Element
         * =======================================
         * [0]  MouseAction on Button_Minimize (toggle minimize)
         * [1]  MouseAction on Button_Maxmimize (toggle maximize)
         * [2]  MouseAction on Button_Close (hide)
         * 
         */
        public Window(Game game, ResourceContentManager rcm, string title, int width, int height)
            : base(game)
        {
            // setting the protected fields
            #region Setting Protected Fields
            this._rcm = rcm;
            this._width = width;
            this._height = height;
            this._windowBounds = new Rectangle((int)this.RelativePosition.X, (int)this.RelativePosition.Y, _width, _height);
            #endregion

            // adding Background, Frame and Panel
            #region Adding Background, Frame & Panel
            base.Add(new Background(game, rcm, "background_", width, height));
            base.Add(new Frame(game, rcm, "frame_", width, height));

            this.Background.RelativePosition = new Vector2(this.Frame.Corner_Top_Left.Width, this.Frame.Corner_Top_Left.Height);
            int bgWidth = width - (this.Frame.Corner_Top_Left.Width + this.Frame.Corner_Bottom_Right.Width);
            int bgHeight = height - (this.Frame.Corner_Top_Left.Height + this.Frame.Corner_Bottom_Right.Height);
            this.Background.Bounds = new Vector2(bgWidth, bgHeight);

            base.Add(new Panel(game, bgWidth, bgHeight));
            this.Panel.RelativePosition = new Vector2(this.Frame.Corner_Top_Left.Width, this.Frame.Corner_Top_Left.Height);
            #endregion

            // adding Button_Close, Button_Minimize & Button_Maximize
            #region Adding Button_Close, Button_Minimize & Button_Maximize
            ContentComponent cc_btn_normal, cc_btn_hover, cc_btn_click;
            cc_btn_normal = new ContentComponent(rcm.Load<Texture2D>("button_minimize_normal"));
            cc_btn_hover = new ContentComponent(rcm.Load<Texture2D>("button_minimize_hover"));
            cc_btn_click = new ContentComponent(rcm.Load<Texture2D>("button_minimize_click"));
            base.Add(new Button(game, cc_btn_normal, cc_btn_hover, cc_btn_click));
            this.Button_Minimize.Visible = false;
            this.Button_Minimize.Enabled = false;

            cc_btn_normal = new ContentComponent(rcm.Load<Texture2D>("button_maximize_normal"));
            cc_btn_hover = new ContentComponent(rcm.Load<Texture2D>("button_maximize_hover"));
            cc_btn_click = new ContentComponent(rcm.Load<Texture2D>("button_maximize_click"));
            base.Add(new Button(game, cc_btn_normal, cc_btn_hover, cc_btn_click));
            this.Button_Maximize.Visible = false;
            this.Button_Maximize.Enabled = false;

            cc_btn_normal = new ContentComponent(rcm.Load<Texture2D>("button_close_normal"));
            cc_btn_hover = new ContentComponent(rcm.Load<Texture2D>("button_close_hover"));
            cc_btn_click = new ContentComponent(rcm.Load<Texture2D>("button_close_click"));
            base.Add(new Button(game, cc_btn_normal, cc_btn_hover, cc_btn_click));
            this.Button_Close.Visible = false;
            this.Button_Close.Enabled = false;
            #endregion

            // adjusting components
            #region Adjusting Components
            Adjust();
            #endregion

            // adding default actions (for the buttons)
            #region Adding Default Actions
            MouseAction ma_tgl_minimize = new MouseAction(this.Button_Minimize, this, ActionCommand.WINDOW_CMD_TGL_MINIMIZE,
                Enums.MouseKeys.Left, Enums.MouseKeyPositions.Pressed, KeyModifier.NONE);
            MouseAction ma_tgl_maximize = new MouseAction(this.Button_Maximize, this, ActionCommand.WINDOW_CMD_TGL_MAXIMIZE,
                Enums.MouseKeys.Left, Enums.MouseKeyPositions.Pressed, KeyModifier.NONE);
            MouseAction ma_tgl_close = new MouseAction(this.Button_Close, this, ActionCommand.CMD_HIDE,
                Enums.MouseKeys.Left, Enums.MouseKeyPositions.Pressed, KeyModifier.NONE);
            #endregion
        }



        #region Window Protected Method - Adjust()
        /// <summary>
        /// adjustes all default components of the window
        /// </summary>
        protected void Adjust()
        {
            this.AdjustPanel();
            this.AdjustBackground();
            this.AdjustButton_Close();
            this.AdjustButton_Maximize();
            this.AdjustButton_Minimize();
        }
        #endregion

        #region Window Protected Method - AdjustButtons()
        /// <summary>
        /// adjustes the buttons (minimize, maximize, close) objects to the current width and usage of other buttons
        /// </summary>
        protected void AdjustButtons()
        {
            this.AdjustButton_Close();
            this.AdjustButton_Maximize();
            this.AdjustButton_Minimize();
        }
        #endregion

        #region Window Protected Method - AdjustButton_Close()
        /// <summary>
        /// adjustes the Button_Close object to the current width and usage of other buttons
        /// </summary>
        protected void AdjustButton_Close()
        {
            int x_coord;
            if (_useFrame)
                x_coord = (int)(this.Frame.Corner_Top_Right.RelativePosition.X - this.Button_Close.Width);
            else x_coord = this.Width - this.Button_Close.Width;

            this.Button_Close.RelativePosition = new Vector2(x_coord, 0);
            this.Button_Close.Visible = this._useButton_Close;
            this.Button_Close.Enabled = this._useButton_Close;
        }
        #endregion

        #region Window Protected Method - AdjustButton_Maximize()
        /// <summary>
        /// adjustes the Button_Maximize object to the current width and usage of other buttons
        /// </summary>
        protected void AdjustButton_Maximize()
        {
            int x_coord;
            if (_useButton_Close)
                x_coord = (int)(this.Button_Close.RelativePosition.X - this.Button_Maximize.Width);
            else
            {
                if (_useFrame)
                    x_coord = (int)(this.Frame.Corner_Top_Right.RelativePosition.X - this.Button_Maximize.Width);
                else x_coord = this.Width - this.Button_Maximize.Width;
            }

            this.Button_Maximize.RelativePosition = new Vector2(x_coord, 0);
            this.Button_Maximize.Visible = this._useButton_Maximize;
            this.Button_Maximize.Enabled = this._useButton_Maximize;
        }
        #endregion

        #region Window Protected Method - AdjustButton_Minimize()
        /// <summary>
        /// adjustes the Button_Minimize object to the current width and usage of other buttons
        /// </summary>
        protected void AdjustButton_Minimize()
        {
            int x_coord;
            if(_useButton_Maximize)
                x_coord = (int)(this.Button_Maximize.RelativePosition.X - this.Button_Minimize.Width);
            else if (_useButton_Close)
                x_coord = (int)(this.Button_Close.RelativePosition.X - this.Button_Minimize.Width);
            else
            {
                if (_useFrame)
                    x_coord = (int)(this.Frame.Corner_Top_Right.RelativePosition.X - this.Button_Minimize.Width);
                else x_coord = this.Width - this.Button_Minimize.Width;
            }

            this.Button_Minimize.RelativePosition = new Vector2(x_coord, 0);
            this.Button_Minimize.Visible = this._useButton_Minimze;
            this.Button_Minimize.Enabled = this._useButton_Minimze;
        }
        #endregion 

        #region Window Protected Method - AdjustPanel()
        /// <summary>
        /// adjustes the Panel object to the current width and height
        /// </summary>
        protected void AdjustPanel()
        {
            this.Panel.RelativePosition = new Vector2(this.Frame.Corner_Top_Left.Width, this.Frame.Corner_Top_Left.Height);
            int pWidth = this._width - (this.Frame.Corner_Top_Left.Width + this.Frame.Corner_Bottom_Right.Width);
            int pHeight = this._height - (this.Frame.Corner_Top_Left.Height + this.Frame.Corner_Bottom_Right.Height);
            this.Panel.Bounds = new Vector2(pWidth, pHeight);
        }
        #endregion

        #region Window Protected Method - AdjustBackground()
        /// <summary>
        /// adjustes the background object to the current width and height
        /// </summary>
        protected void AdjustBackground()
        {
            if (_useFrame)
            {
                this.Background.RelativePosition = new Vector2(this.Frame.Corner_Top_Left.Width, this.Frame.Corner_Top_Left.Height);
                int bgWidth = this._width - (this.Frame.Corner_Top_Left.Width + this.Frame.Corner_Bottom_Right.Width);
                int bgHeight = this._height - (this.Frame.Corner_Top_Left.Height + this.Frame.Corner_Bottom_Right.Height);
                this.Background.Bounds = new Vector2(bgWidth, bgHeight);
            }
            else
            {
                this.Background.RelativePosition = new Vector2(0, 0);
                int bgWidth = this._width;
                int bgHeight = this._height;
                this.Background.Bounds = new Vector2(bgWidth, bgHeight);
            }
        }
        #endregion

        #region Window Protected Method - Resize(int width, int height)
        /// <summary>
        /// resizes the window and the necessary children on it
        /// </summary>
        /// <param name="width">width to set for the window</param>
        /// <param name="height">height to set for the window</param>
        protected override void Resize(int width, int height)
        {
            this._width = width;
            this._height = height;

            if (_useFrame)
            {
                this.Frame.Bounds = new Vector2(this._width, this._height);
                int bgWidth = this._width - (this.Frame.Corner_Top_Left.Width + this.Frame.Corner_Bottom_Right.Width);
                int bgHeight = this._height - (this.Frame.Corner_Top_Left.Height + this.Frame.Corner_Bottom_Right.Height);
                this.Background.RelativePosition = new Vector2(this.Frame.Corner_Top_Left.Width, this.Frame.Corner_Top_Left.Height);
                this.Background.Bounds = new Vector2(bgWidth, bgHeight);
                if (_windowState != Enums.WindowState.Minimized)
                {
                    this.Panel.RelativePosition = new Vector2(this.Frame.Corner_Top_Left.Width, this.Frame.Corner_Top_Left.Height);
                    this.Panel.Bounds = new Vector2(bgWidth, bgHeight);
                }
            }
            else
            {
                this.Frame.Bounds = new Vector2(this._width, this._height);
                this.Frame.Visible = _useFrame;
                this.Frame.Enabled = _useFrame;
                this.Background.RelativePosition = new Vector2(0, 0);
                this.Background.Bounds = new Vector2(this._width, this._height);
                if (_windowState != Enums.WindowState.Minimized)
                {
                    this.Panel.RelativePosition = new Vector2(0, 0);
                    this.Panel.Bounds = new Vector2(this._width, this._height);
                }
            }

            AdjustButtons();
        }
        #endregion



        #region Window Public Method - Add(GIComponent item)
        /// <summary>
        /// adds a GIComponent to the window (added on the content area/Panel)
        /// </summary>
        /// <param name="item">item to add to the window</param>
        public new void Add(GIComponent item)
        {
            this.Panel.Add(item);
        }
        #endregion

        #region Window Public Method - Remove(GIComponent item)
        /// <summary>
        /// removes a GIComponent from the window (removed from the content area/Panel)
        /// </summary>
        /// <param name="item">item to remove from the window</param>
        /// <returns>true if component was removed, false otherwise</returns>
        public new bool Remove(GIComponent item)
        {
            return this.Panel.Remove(item);
        }
        #endregion

        #region Window Public Method - UnbindGIC(int index)
        /// <summary>
        /// unbinds/frees a GIComponent from the window
        /// </summary>
        /// <param name="index">indes on which the component will be unbound</param>
        /// <returns>the ownerless component</returns>
        public new GIComponent UnbindGIC(int index)
        {
            return this.Panel.UnbindGIC(index);
        }
        #endregion


        #region Window Public Override Method - ExecuteCommand(string command)
        /// <summary>
        /// executes a command on the component (see ActionCommand class for list)
        /// </summary>
        /// <param name="command">command to execute</param>
        public override void ExecuteCommand(string command)
        {
            base.ExecuteCommand(command);

            #region ExecuteCommand | WINDOW_CMD_MINIMIZE
            if (command.Equals(ActionCommand.WINDOW_CMD_MINIMIZE))
            {
                if (this._minimizable && this._windowState != Enums.WindowState.Minimized)
                {
                    if (this._windowState == Enums.WindowState.Normal)
                        this._windowBounds = new Rectangle((int)this.RelativePosition.X, (int)this.RelativePosition.Y, this.Width, this.Height);
                    this._windowState = Enums.WindowState.Minimized;

                    this.Background.Visible = false;
                    this.Background.Enabled = false;
                    this.Panel.Visible = false;
                    this.Panel.Enabled = false;

                    this.Bounds = new Vector2(200, this.Frame.Border_Top.Height + 5);
                    this.RelativePosition = new Vector2(this._windowBounds.X, this._windowBounds.Y);
                }
            }
            #endregion

            #region ExecuteCommand | WINDOW_CMD_MAXIMIZE
            else if (command.Equals(ActionCommand.WINDOW_CMD_MAXIMIZE))
            {
                if (this._maximizable && this._windowState != Enums.WindowState.Maximized)
                {
                    if (this._windowState == Enums.WindowState.Normal)
                        this._windowBounds = new Rectangle((int)this.RelativePosition.X, (int)this.RelativePosition.Y, this.Width, this.Height);
                    this._windowState = Enums.WindowState.Maximized;

                    this.Background.Visible = true;
                    this.Background.Enabled = true;
                    this.Panel.Visible = true;
                    this.Panel.Enabled = true;

                    Form gameForm = (Form)Form.FromHandle(this._game.Window.Handle);

                    this.Bounds = new Vector2(gameForm.DisplayRectangle.Width, gameForm.DisplayRectangle.Height);
                    this.RelativePosition = new Vector2(gameForm.DisplayRectangle.X, gameForm.DisplayRectangle.Y);
                }
            }
            #endregion

            #region ExecuteCommand | WINDOW_CMD_TGL_MINIMIZE
            else if (command.Equals(ActionCommand.WINDOW_CMD_TGL_MINIMIZE))
            {
                if (this._windowState != Enums.WindowState.Minimized)
                    this.ExecuteCommand(ActionCommand.WINDOW_CMD_MINIMIZE);
                else
                {
                    this.ExecuteCommand(ActionCommand.WINDOW_CMD_NORMALIZE);
                    this.ExecuteCommand(ActionCommand.WINDOW_CMD_MAXIMIZE);
                    this.ExecuteCommand(ActionCommand.WINDOW_CMD_NORMALIZE);
                }
            }
            #endregion

            #region ExecuteCommand | WINDOW_CMD_TGL_MAXIMIZE
            else if (command.Equals(ActionCommand.WINDOW_CMD_TGL_MAXIMIZE))
            {
                if (this._windowState != Enums.WindowState.Maximized)
                    this.ExecuteCommand(ActionCommand.WINDOW_CMD_MAXIMIZE);
                else
                    this.ExecuteCommand(ActionCommand.WINDOW_CMD_NORMALIZE);
            }
            #endregion

            #region ExecuteCommand | WINDOW_CMD_NORMALIZE
            else if(command.Equals(ActionCommand.WINDOW_CMD_NORMALIZE))
            {
                this._windowState = Enums.WindowState.Normal;

                this.Background.Visible = true;
                this.Background.Enabled = true;
                this.Panel.Visible = true;
                this.Panel.Enabled = true;

                this.Bounds = new Vector2(this._windowBounds.Width, this._windowBounds.Height);
                this.RelativePosition = new Vector2(this._windowBounds.X, this._windowBounds.Y);
            }
            #endregion

            #region ExecuteCommand | WINDOW_CMD_RESIZE
            else if (command.Equals(ActionCommand.WINDOW_CMD_RESIZE))
            {
                if (this._resizable && this._windowState == Enums.WindowState.Normal)
                {
                    // get the current mouse position
                    Vector2 mousePos = new Vector2(_ms.X, _ms.Y);
                    // get the mouse position from the last update cycle
                    Vector2 mousePosOld = new Vector2(_oms.X, _oms.Y);
                    // add the difference from (current mouse position and old mouse position) to the current target's position
                    float xdiff = mousePos.X - mousePosOld.X;
                    float ydiff = mousePos.Y - mousePosOld.Y;

                    if (this.Bounds.X >= 200
                        && this.Bounds.X < this._game.Window.ClientBounds.Width +1)
                        this.Bounds += new Vector2(xdiff, 0);
                    else if(this.Bounds.X > this._game.Window.ClientBounds.Width)
                        this.Bounds += new Vector2(-1, 0);
                    else
                        this.Bounds = new Vector2(200, this.Bounds.Y);

                    int height = this.Frame.Border_Top.Height + 5 + this.Frame.Border_Bottom.Height;
                    if (this.Background.UseDecoration)
                        height += this.Background.Decoration.Height;

                    if (this.Bounds.Y >= height
                        && this.Bounds.Y < this._game.Window.ClientBounds.Height +1)
                        this.Bounds += new Vector2(0, ydiff);
                    else if (this.Bounds.Y > this._game.Window.ClientBounds.Height)
                        this.Bounds += new Vector2(0, -1);
                    else
                        this.Bounds = new Vector2(this.Bounds.X, height);
                }
            }
            #endregion

            /*
            if (command.Equals("newWindow"))
            {

                Window win = new Window(this._game, XNAGuiLib.Core.Resources.ResourceManager.Instance(this._game, Enums.RCM.Vista_Graphit), "window_", 480, 320);
                win.RelativePosition = new Vector2(0, 0);
                win.FrameHeadSize = Enums.FrameHeadStyle.Medium;
                win.UseButton_Maximize = false;
                win.UseButton_Minimize = true;
                this._game.Components.Add(win);

                XNAGuiLib.Core.ActionHandling.MouseAction ma_movewin1 = new XNAGuiLib.Core.ActionHandling.MouseAction(win.Frame.Border_Top, win,
                    ActionCommand.CMD_MOVE, Enums.MouseKeys.Left, Enums.MouseKeyPositions.Down, KeyModifier.NONE);

                XNAGuiLib.Core.ActionHandling.MouseAction ma_resize = new MouseAction(win.Frame.Corner_Bottom_Right, win,
                    ActionCommand.WINDOW_CMD_RESIZE, Enums.MouseKeys.Right, Enums.MouseKeyPositions.Down, KeyModifier.NONE);
            }
            */
        }
        #endregion
    }
}